package name.vaccari.matteo.tai.phonedirectory.xpath;

import static org.junit.Assert.*;

import java.io.File;
import java.io.FileNotFoundException;

import org.junit.Test;


public class XPathTest {

	@Test
	public void canLoadADocument() throws Exception {
		XmlDocument document = new XmlDocument(new File("test-resources/books.xml"));
		document.load();
		// no exceptions thrown
	}
	
	@Test
	public void canGetANodeList() throws Exception {
		XmlDocument document = new XmlDocument(new File("test-resources/books.xml"));
		assertEquals(4, document.getNodeList("//book").getLength());
		assertEquals("Giada De Laurentiis", document.getNodeText("//book[@id='everyday-italian']/author"));
	}
	
	@Test
	public void shouldThrowWhenThereIsNoFile() throws Exception {
		try {
			XmlDocument document = new XmlDocument(new File("not existent"));
			document.load();
			fail("non ha lanciato");
		} catch (FileNotFoundException expected) {
			// OK
		}
	}
}
